package controller.v2;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import model.AddressVO;
import model.CatVO;
import model.DicVO;
import model.GoodVO;
import model.MemberVO;
import model.OrderEvaluateVO;
import model.PageEarnVO;
import model.PromotionGoodVO;
import model.PromotionVO;
import model.SaleVO;

import model.StandardVO;

import model.ShowwindowVO;

import service.v2.CatService;
import service.v2.ConfigService;
import service.v2.DicService;
import service.v2.GoodService;
import service.v2.GoodStandardService;
import service.v2.MaterialService;
import service.v2.MemberCartServise;
import service.v2.MemberItemService;
import service.v2.MemberRecordService;
import service.v2.MemberService;
import service.v2.PackageService;
import service.v2.PromotionService;
import service.v2.SaleService;
import service.v2.ShowwindowService;
import util.DateParseUtil;
import util.PackageUtil;
import util.PropertieUtil;
import util.StringUtil;

@RequestMapping("/v2/good")
@Controller
public class GoodController {
	@Autowired
	private GoodService goodService;
	@Autowired
	private MemberCartServise cartService;
	@Autowired
	private CatService catService;
	@Autowired
	private MemberService memberService;
	@Autowired
	private GoodStandardService goodStandardService;
	@Autowired
	private ConfigService configService;
	@Autowired
	private MemberRecordService memberRecordService;
	@Autowired
	private MaterialService materialService;
	@Autowired
	private SaleService saleService;
	@Autowired
	private ShowwindowService showwindowService;
	@Autowired
	private MemberItemService memberItemService;
	@Autowired
	private PackageService packageService;
	@Autowired
	private DicService dicService;
	@Autowired
	private PromotionService promotionService;
	@Autowired
	private MemberCartServise memberCartServise;
	/**
	 * 商品详情
	 */
	@ResponseBody
	@RequestMapping(value="/goodDetail/{id}",method=RequestMethod.GET)
	public Object adList(@RequestHeader(value = "LANG", required = false) String lang,@PathVariable String id,HttpServletRequest request, HttpServletResponse response,@RequestHeader(value = "OS", required = false) String os,@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO, ShowwindowVO showwindowVO) throws Exception{
       
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		
		Map map = new HashMap();
		MemberVO m_vo=new MemberVO();
		String level_name= dicService.getNameById(PropertieUtil.loadPropertie("expert_level"));
		String level_name_en= dicService.getNamEneById(PropertieUtil.loadPropertie("expert_level"));
		m_vo.setLevel(PropertieUtil.loadPropertie("expert_level"));
		m_vo.setLevel_name(level_name);
		m_vo.setLevel_name(level_name_en);
		m_vo.setM_level_logo(configService.loadConfig("MEMBER_LEVEL_LOGO123"));
		//查询商品
		String file_cat = PropertieUtil.loadPropertie("good_imgs");//66
		GoodVO good = goodService.getGoodById(id,file_cat);
		if(good==null){
			return PackageUtil.packageParams(10101,"商品已下架或删除","",""); 
		}   
		int num = 0;
		if (token != null && member_id != null) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token, os);
			if (memberVO == null) {
				return PackageUtil.packageParams(403, "forbidden", "", "");
			}else{
				if(PropertieUtil.loadPropertie("common_level").equals(memberVO.getLevel())||
				    PropertieUtil.loadPropertie("vip_level").equals(memberVO.getLevel())){
					map.put("memberVO", m_vo);
				}else{
					map.put("memberVO", memberVO);
				}
				//购物车数量
				num = cartService.getCartNum(member_id);
				//保存记录
				memberRecordService.insertRecord(member_id, id);
				
				int level_num = materialService.checkGtLevel(member_id,PropertieUtil.loadPropertie("vip_level"));
				if(level_num > 0){
					//good = materialService.processShareInfo(good);
					Map shareInfomap = materialService.newProcessShareInfo(good.getJoin_award(), good.getJoin_award_money(), good.getBuy_type(), good.getMin_ticket());
					good.setShare_info(shareInfomap.get("share_info").toString());
					good.setMin_share_info(shareInfomap.get("min_share_info").toString());
				}
				//是否添加过橱窗
				showwindowVO.setGood_id(id);
				showwindowVO.setMember_id(member_id);
				ShowwindowVO vo = showwindowService.checkWindowGood(showwindowVO);
				map.put("window_state", vo==null?0:1);
				map.put("last_window", vo==null?"":vo.getCat_name());//最后添加的橱窗
				//购买新手礼包用 套餐信息
				if("Y".equals(good.getPackage_yn())){
					String rate = "";
					if(PropertieUtil.loadPropertie("vip_level").equals(memberVO.getLevel()) || PropertieUtil.loadPropertie("common_level").equals(memberVO.getLevel())){
						rate = memberItemService.getRateByLevel(PropertieUtil.loadPropertie("primary_level"));
					}else{
						rate = memberItemService.getRateByLevel(memberVO.getLevel());
					}
					map.put("rate", rate);
					String recharge_ticket = packageService.getPackageByGood(id);
					map.put("recharge_ticket", recharge_ticket);
					map.put("ticket_logo", configService.loadConfig("TICKET_LOGO"));
				}
			}
		}else {
			map.put("memberVO", m_vo);
		}
		//根据购买类型和会员级别显示优惠购
		String  privilege_price = goodService.processPrivilegePrice(good.getBuy_type(), good.getMin_ticket(), good.getMin_ticket_price(), memberVO, configService.loadConfig("SHORT_TICKET_NAME"));
		good.setPrivilege_price(privilege_price);
		String member_price = goodService.processMemberPrice(good.getMin_sell_price(), good.getBuy_type(), good.getMin_ticket(), good.getMin_ticket_price(), memberVO);
		good.setMember_price(member_price);
		String deduction_info = goodService.processDeductionInfo(good.getBuy_type(), good.getMin_ticket(), good.getMin_ticket_price(), memberVO, configService.loadConfig("TICKET_NAME"), good.getCountry());
		good.setDeduction_info(deduction_info);
		//加入会员 一年可省
		String save_info = goodService.getSaveInfo(memberVO);
		good.setSave_info(save_info);
		//评价
		OrderEvaluateVO evalu = goodService.getOneEvaluByGoodId(id);
		if(evalu==null){
			 evalu = new  OrderEvaluateVO();
			 map.put("total_record", 0);
			 map.put("total_pic_record", 0);
		}else{
			map.put("total_record", evalu.getTotal_record());
			map.put("total_pic_record", evalu.getTotal_record());
		}
		//大家都在看促销信息
		List<GoodVO> hotWatch = goodService.getHotWatchByGoodId(id);
		good.setHotWatch(hotWatch);
		goodService.processPromotionList(good.getHotWatch(), memberVO);
		map.put("good", good);
		map.put("cart_num", num);
		map.put("url", host+version+"/page/goodDetail?good_id="+good.getGood_id());
		
	
		Map share = new HashMap();
		//分享链接IMG
		share.put("image",good.getImg()+"?x-oss-process=image/resize,h_100");
		//分享链接URLz
		share.put("url", configService.loadConfig("WECHAT_HOST")+"/goodDetail?good_id="+good.getGood_id()+"&ym_share_inviteno="+memberVO.getInvite_no()+"&cat_id="+good.getCat_id());
		//分享链接title
		share.put("title",  good.getName());
		//分享链接content
		share.put("content", configService.loadConfig("SHARE_GOOD_DETAIL_CONTENT"));
		
		map.put("records", evalu);
		map.put("share", share);
		
		//套餐商品deliveryAddressModify时获取套餐商品名
		String good_package_name = goodService.getGoodPackageName(good.getGood_id());
		map.put("good_package_name", good_package_name);
		//承诺描述
		List<DicVO> promiseList = dicService.getListByParent(PropertieUtil.loadPropertie("good_promise"), good);
		map.put("promiseList", promiseList);
		//促销
		PromotionGoodVO promotionGoodVO = promotionService.getListByGood(good.getGood_id(), memberVO,lang);
		map.put("promotionGood", promotionGoodVO);
		
		//配送地址
		MemberVO addressVO=goodService.getAddressDefaultInfo(member_id,good.getGood_id(),lang);
		map.put("addressVO", addressVO);
		
		String isBought="0"; // NO 没买过 YES 买过
		int packageCount = memberCartServise.getPackageCountByMemberId(member_id);
		if(packageCount>0){
			isBought="1";
		}
		map.put("isBought", isBought);
		return PackageUtil.packageParams(200,"success",map,"");
	}
	
	/**
	 * 商品列表
	 */
	@ResponseBody
	@RequestMapping(value="/goodList",method=RequestMethod.GET)
	public Object goodList(@RequestHeader(value = "LANG", required = false) String lang,
			@RequestHeader(value = "OS", required = false) String os,
			@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request,
			HttpServletResponse response, GoodVO goodVO,
			@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO) throws Exception {
		if (goodVO.getSearch_str() != null && !"".equals(goodVO.getSearch_str())) {
			memberRecordService.insertRecordStr(member_id, goodVO.getSearch_str());
		}
		
		goodVO.setLang(lang);
		int total = goodService.getTotal(goodVO);
		goodVO.setPagination(goodVO.getPage_index(), total+"");
		List<GoodVO> list = goodService.getGoodList(goodVO);
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			goodService.processImg(list, screenwidth,2);
		}
		
		if (token != null && member_id != null) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token, os);
			if (memberVO == null) {
				return PackageUtil.packageParams(403, "forbidden", "", "");
			}
		}
		list = goodService.processGoodList(list, memberVO, "券");
		List<CatVO> catList = catService.getCatListByGoodInfo(goodVO);
		Map map = new HashMap();
		map.put("pagination", goodVO);
		map.put("list", list);
		map.put("cat_list", catList);
		return PackageUtil.packageParams(200,"success",map,"");
	}
	
	/**
	 * 分类列表
	 * @param 1级菜单id cat_id
	 */
	@ResponseBody
	@RequestMapping(value="/childCatList",method=RequestMethod.GET)
	public Object childCatList(HttpServletRequest request, HttpServletResponse response, CatVO catVO) throws Exception{
		if(catVO.getCat_id() == null || "".equals(catVO.getCat_id())){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		CatVO cat = catService.getCatById(catVO.getCat_id());
		//全部 添加
		catService.addFirtAllCat(cat.getCatList());
		return PackageUtil.packageParams(200,"success",cat,"");
	}
	
	/**
	 * 特殊商品列表
	 * @param cat_id 特殊商品分类
	 */
	@ResponseBody
	@RequestMapping(value="/specialGoodList",method=RequestMethod.GET)
	public Object specialGoodList(@RequestHeader(value = "LANG", required = false) String lang,
			@RequestHeader(value = "OS", required = false) String os,
			@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request,
			HttpServletResponse response, GoodVO goodVO,
			@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO) throws Exception {
		if(goodVO.getCat_id() == null || "".equals(goodVO.getCat_id())){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		if (token != null && member_id != null) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token,os);
			if (memberVO == null) {
				return PackageUtil.packageParams(403, "forbidden", "", "");
			}
		}
		goodVO.setLang(lang);
		Map map = specialGoodListMap(screenwidth, goodVO, memberVO, goodService, catService);
		return PackageUtil.packageParams(200,"success",map,"");
	}

	public Map specialGoodListMap(String screenwidth, GoodVO goodVO, MemberVO memberVO, GoodService goodService, CatService catService) throws Exception {
		if(PropertieUtil.loadPropertie("package_cat").equals(goodVO.getCat_id())){
			goodVO.setPackage_yn("Y");
		}
		int total = goodService.getSpecialTotal(goodVO);
		goodVO.setPagination(goodVO.getPage_index(), total+"");
		List<GoodVO> list = goodService.getSpecialGoodList(goodVO);
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			goodService.processImg(list, screenwidth,2);
		}
		if(!PropertieUtil.loadPropertie("package_cat").equals(goodVO.getCat_id())){
			list = goodService.processGoodList(list, memberVO, "券");
		}
		CatVO catVO = catService.getCatById(goodVO.getCat_id());
		catVO = catService.packageShareInfo(catVO);
		Map map = new HashMap();
		map.put("goodList", list);
		map.put("cat", catVO);
		map.put("pagination", goodVO);
		return map;
	}
	
	/**
	 * 特卖商品列表
	 */
	@ResponseBody
	@RequestMapping(value="/saleList",method=RequestMethod.GET)
	public Object saleIndex(@RequestHeader(value = "OS", required = false) String os,@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response, GoodVO goodVO ,@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO,SaleVO saleVO) throws Exception{
		/*if(saleVO.getSale_id()==null || "".equals(saleVO.getSale_id())){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}*/
		saleVO.setFile_cat(PropertieUtil.loadPropertie("good_imgs"));
		int total = saleService.getSaleTotal(saleVO);
		saleVO.setPagination(saleVO.getPage_index(), total+"");
		List<SaleVO> list = saleService.getSaleList(saleVO);

		String invite_no = "";
		if (token != null && member_id != null) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token,os);
			if (memberVO == null) {
				return PackageUtil.packageParams(403, "forbidden", "", "");
			}
			invite_no = memberVO.getInvite_no();
		}
		for (SaleVO vo : list) {
			goodService.processGoodList(vo.getGoodList(), memberVO, "券");
			goodService.setShareMsg(vo.getGoodList(),invite_no);
		}
		Map map = new HashMap();
		map.put("saleList", list);
		map.put("pagination", saleVO);
		return PackageUtil.packageParams(200,"success",map,""); 
	}

	/**
	 * 商品详情部分选和全选请求接口
	 * @param os
	 * @param good_id
	 * @param type_id
	 * @param type_child_name
	 * @param searchState
	 * @param last_type_id
	 * @param last_type_child_name
	 * @param token
	 * @param member_id
	 * @param memberVO
	 * @return
	 * @throws Exception
	 */
	
	@ResponseBody
	@RequestMapping(value="/goodStandardDetails",method=RequestMethod.GET)
	public Object goodStandardDetails(@RequestHeader(value = "OS", required = false) String os,String good_id,String type_id,String type_child_name,String searchState,String last_type_id,String last_type_child_name,@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO) throws Exception{
		
		if (token != null && member_id != null) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token, os);
			if (memberVO == null) {
				return PackageUtil.packageParams(403, "forbidden", "", "");
			}
		}
		
		if(good_id == null || "".equals(good_id)){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		if(type_id == null || "".equals(type_id)){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		if(type_child_name == null || "".equals(type_child_name)){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		if(searchState == null || "".equals(searchState)){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		if("1".equals(searchState)&&(last_type_id==null||"".equals(last_type_id))){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		if("1".equals(searchState)&&(last_type_child_name==null||"".equals(last_type_child_name))){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		//searchState 0 部分选 1 全选
		List<StandardVO> standard = (List<StandardVO>) goodService.dealNewStadardDetails(good_id,type_id,type_child_name,searchState,last_type_id,last_type_child_name,memberVO);
		return PackageUtil.packageParams(200,"success",standard,""); 
	}


	/**
	 *商品分享次数统计
	 *@param good_id
	 *@param share_type 1:商品详情分享 2: 橱窗 3:个人主页 4:橱窗商品详情
	 *@param member_id 要分享的个人主页member_id
	 *@param cat_id 橱窗分类id
	 *@param window_id 橱窗详情
	
	 */
	@ResponseBody
	@RequestMapping(value="/shareStatistics",method=RequestMethod.POST)
	public Object shareStatistics(HttpServletRequest request, HttpServletResponse response,GoodVO goodVO,
			String share_type,String member_id,String cat_id,String window_id) throws Exception{
		
		if(share_type == null || "".equals(share_type)){
			return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
		}
		
		if(!"1".equals(share_type) && !"2".equals(share_type) && !"3".equals(share_type) && !"4".equals(share_type)){
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		
		if("1".equals(share_type)){
			if(goodVO.getGood_id() == null || "".equals(goodVO.getGood_id())){
				return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
			}
			goodService.updataShareTimes(goodVO);
		}
		
		if("2".equals(share_type)){
			if(cat_id == null || "".equals(cat_id)){
				return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
			}
			//橱窗 分享计数
			showwindowService.updataCatWindowListShareTimes(cat_id);
		}
		
		if("3".equals(share_type)){
			if(member_id == null || "".equals(member_id)){
				return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
			}
			//个人主页 分享计数
			memberService.updataMyWindowShareTimes(member_id);
		}
		
		if("4".equals(share_type)){
			if(window_id == null || "".equals(window_id)){
				return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
			}
			//橱窗详情分享
			showwindowService.updataWindowDetailShareTimes(window_id);
		}
		
		return PackageUtil.packageParams(200,"success","",""); 

	}
	/**
	 * 选择修改地址更新
	 * @param address_id
	 * @param city_id
	 */
	@ResponseBody 
	@RequestMapping(value="/deliveryAddressModify",method=RequestMethod.POST)
	public Object deliveryAddressModify(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader(value = "OS", required = false) String os,@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response, @RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO,String address_id,String city_id) throws Exception{
		MemberVO city_info=null;
		int count1=0;
		int count2=0;
		count2 =memberService.selectLibCity(city_id);
		if(lang==null){
			count1 =memberService.selectMemberCart(address_id);
			if(count1+count2==0){
				return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
			}
			 city_info=goodService.updataDeliveryAddress(member_id,address_id,city_id);
		}else{
			count1 =memberService.selectMemberCartEn(address_id);
			if(count1+count2==0){
				return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
			}
			city_info=goodService.updataDeliveryAddressEn(member_id,address_id,city_id);
		}
		return PackageUtil.packageParams(200,"success",city_info,"");
	}
	/**
	 * 获取配送运费
	 * @param address_id
	 * @param city_id
	 * @param good_id
	 * @param num
	 * @param member_id
	 */
	@ResponseBody 
	@RequestMapping(value="/getFreight",method=RequestMethod.GET)
	public Object getFreight(@RequestHeader(value = "LANG", required = false) String lang,@RequestHeader(value = "OS", required = false) String os,@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request, HttpServletResponse response, @RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, String country_id,MemberVO memberVO,String address_id,String city_id,String good_id,String num) throws Exception{
		Map map = new HashMap();
		int count1=0;
		int count2=0;
		//验证数量
		if(num==null || "".equals(num)||!StringUtil.isNumeric(num)){
			return PackageUtil.packageParams(10000,"参数错误，请参考API文档","",""); 
		}
		//验证参数
		if(good_id==null || "".equals(good_id)){
			return PackageUtil.packageParams(10001,"缺少必选参数，请参考API文档","",""); 
		}
		count2 =memberService.selectLibCity(city_id);
		if(lang==null){
			count1 =memberService.selectMemberCart(address_id);
			if(count1+count2==0){
				return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
			}
			map = goodService.getGoodsFreightAndDeliveryAddressState(member_id,address_id,city_id,good_id,num);
		}else{
			count1 =memberService.selectMemberCartEn(address_id);
			if(count1+count2==0){
				return PackageUtil.packageParams(10001,"缺少必选参数","",""); 
			}
			map = goodService.getGoodsFreightAndDeliveryAddressStateEn(member_id,address_id,city_id,good_id,num,country_id);
		}
		return PackageUtil.packageParams(200,"success",map,"");
	}
	/**
	 * @param token 令牌
	 * @param member_id 用户ID
	 * @return 会员专享画面
	 * @throws Exception 
	 */
	@RequestMapping(value="/exclusiveMembership",method=RequestMethod.GET)
	public String exclusiveMembership(@RequestHeader(value = "LANG", required = false) String lang,
			@RequestHeader (value="OS", required=false) String os,
			@RequestHeader (value="AUTHORIZATION", required=false) String token,
			@RequestHeader (value="SECRET", required=false)  String member_id,
			@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth,HttpServletRequest request, HttpServletResponse response,MemberVO memberVO,String isJSON) throws Exception{
		if(os != null){
			os = os.toLowerCase();
		}
		if (token != null && member_id != null) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token, os);
			if (memberVO == null) {
				response.setContentType("text/json;charset=utf-8");   
				PrintWriter out = response.getWriter(); 
				out.print(JSON.toJSONString(PackageUtil.packageParams(403, "forbidden", "", "")));
				out.flush();
				out.close();
				return null;
			}
		}else{
			memberVO.setLevel(PropertieUtil.loadPropertie("expert_level"));
		}
		List<GoodVO> goodList=new ArrayList<GoodVO>();
		List<CatVO> memberCatList =new ArrayList<CatVO>();
		if(lang==null){
			memberCatList = catService.getMemberCatList(PropertieUtil.loadPropertie("member_cat"), PropertieUtil.loadPropertie("member_default_cat"));
		}else{
			memberCatList = catService.getMemberCatList(PropertieUtil.loadPropertie("inter_member_cat"), PropertieUtil.loadPropertie("inter_member_default_cat"));

		}
		for (CatVO vo : memberCatList) {
			GoodVO goodVO = new GoodVO();
			goodVO.setCat_id(vo.getCat_id());
			goodVO.setPage_yn(null);
			goodVO.setLang(lang);
			if(PropertieUtil.loadPropertie("package_cat").equals(goodVO.getCat_id())){
				goodVO.setPackage_yn("Y");
			}
			int total = goodService.getSpecialTotal(goodVO);
			goodVO.setPagination(goodVO.getPage_index(), total+"");
			List<GoodVO> list = goodService.getSpecialGoodList(goodVO);
			
			//图片缩放
			if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
				goodService.processImg(list, screenwidth,2);
			}
			if(!PropertieUtil.loadPropertie("package_cat").equals(goodVO.getCat_id())){
				list = goodService.processGoodList(list, memberVO, "券");
			}
			List<GoodVO> list1 = goodService.packageGoodPrice(list);
			goodVO.setGoodList(list1);
			goodVO.setCat_name(vo.getName());
			goodList.add(goodVO);
		}
		if(!"1".equals(isJSON)){
			request.setAttribute("goodList", goodList);
			request.setAttribute("os", os);
			return "/app/good/exclusiveMembership";
		}else{
			Map map  =  new HashMap();
			map.put("goodList", goodList);
			response.setContentType("text/json;charset=utf-8");
	        PrintWriter out = response.getWriter();
	        out.print(JSON.toJSONString(PackageUtil.packageParams(200, "success", map, "")));
	        out.flush();
	        out.close();
	      return null;
		}
	}
	/**
	 * 新手礼包网页
	 */
	@RequestMapping(value="/specialGoodListWeb",method=RequestMethod.GET)
	public String specialGoodListWeb(@RequestHeader(value = "LANG", required = false) String lang,
			@RequestHeader(value = "OS", required = false) String os,
			@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request,
			HttpServletResponse response, GoodVO goodVO,
			@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO) throws Exception {
		if(os != null){
			os = os.toLowerCase();
		}
		if (token != null && member_id != null) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token,os);
			if (memberVO == null) {
				response.setContentType("text/json;charset=utf-8");   
				PrintWriter out = response.getWriter(); 
				out.print(JSON.toJSONString(PackageUtil.packageParams(403, "forbidden", "", "")));
				out.flush();
				out.close();
				return null;
			}
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		
		String isBought="NO"; // NO 没买过 YES 买过
		goodVO.setLang(lang);
		goodVO.setCat_id("200");
		if(PropertieUtil.loadPropertie("package_cat").equals(goodVO.getCat_id())){
			goodVO.setPackage_yn("Y");
		}
		int total = goodService.getSpecialTotal(goodVO);
		goodVO.setPagination(goodVO.getPage_index(), total+"");
		List<GoodVO> list = goodService.getSpecialGoodList(goodVO);
		
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			goodService.processImg(list, screenwidth,2);
		}
		if(!PropertieUtil.loadPropertie("package_cat").equals(goodVO.getCat_id())){
			list = goodService.processGoodList(list, memberVO, "券");
		}
		List<GoodVO> list1 = goodService.packageGoodPrice(list);
		int packageCount = memberCartServise.getPackageCountByMemberId(member_id);
		if(packageCount>0){
			isBought="YES";
		}
			
		request.setAttribute("isBought", isBought);
		request.setAttribute("goodList", list1);
		request.setAttribute("os", os);
		request.setAttribute("memberId", member_id);
		request.setAttribute("token", token);
		request.setAttribute("settlementPackageGoodsOne_url",host+version+"/membercart/settlementPackageGoodsOne");
		//request.setAttribute("settlementPackageGoodsOne_url","http://10.0.0.68:8080/v2/membercart/settlementPackageGoodsOne");
		return "/app/good/specialGoodListWeb";
	}
	/**
	 * 新手礼包网页
	 */
	@RequestMapping(value="/specialGoodListWebItem",method=RequestMethod.GET)
	public String specialGoodListWebItem(@RequestHeader(value = "LANG", required = false) String lang,
			@RequestHeader(value = "OS", required = false) String os,
			@RequestHeader(value = "SCREENWIDTH", required = false) String screenwidth, HttpServletRequest request,
			HttpServletResponse response, GoodVO goodVO,
			@RequestHeader(value = "AUTHORIZATION", required = false) String token,
			@RequestHeader(value = "SECRET", required = false) String member_id, MemberVO memberVO) throws Exception {
		if(os != null){
			os = os.toLowerCase();
		}
		if (!"".equals(token) && !"".equals(member_id)) {
			memberVO = memberService.getMemberByIdCheck(member_id ,token,os);
			if (memberVO == null) {
				response.setContentType("text/json;charset=utf-8");   
				PrintWriter out = response.getWriter(); 
				out.print(JSON.toJSONString(PackageUtil.packageParams(403, "forbidden", "", "")));
				out.flush();
				out.close();
				return null;
			}
		}
		String host = configService.loadConfig("HOST");
		String version=configService.loadConfig("VERSION");
		goodVO.setLang(lang);
		goodVO.setCat_id("200");
		if(PropertieUtil.loadPropertie("package_cat").equals(goodVO.getCat_id())){
			goodVO.setPackage_yn("Y");
		}
		int total = goodService.getSpecialTotal(goodVO);
		goodVO.setPagination(goodVO.getPage_index(), total+"");
		List<GoodVO> list = goodService.getSpecialGoodList(goodVO);
		
		//图片缩放
		if(screenwidth != null && StringUtil.isNumeric(screenwidth)){
			goodService.processImg(list, screenwidth,2);
		}
		if(!PropertieUtil.loadPropertie("package_cat").equals(goodVO.getCat_id())){
			list = goodService.processGoodList(list, memberVO, "券");
		}
		List<GoodVO> list1 = goodService.packageGoodPrice(list);
		request.setAttribute("goodList", list1);
		request.setAttribute("os", os);
		request.setAttribute("memberId", member_id);
		request.setAttribute("token", token);
		request.setAttribute("settlementPackageGoodsOne_url",host+version+"/membercart/settlementPackageGoodsOne");
		//request.setAttribute("settlementPackageGoodsOne_url","http://10.0.0.68:8080/v2/membercart/settlementPackageGoodsOne");
		return "/app/good/specialGoodListWebItem";
	}
	
}
